package taller2.view.menus;

import java.awt.GridBagLayout;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JToggleButton;

import taller2.controller.listeners.selectionMenu.BFSButtonListener;
import taller2.controller.listeners.selectionMenu.CycleDetectionListener;
import taller2.controller.listeners.selectionMenu.DFSButtonListener;
import taller2.controller.listeners.selectionMenu.DijkstraButtonListener;
import taller2.controller.listeners.selectionMenu.FloydButtonListener;
import taller2.controller.listeners.selectionMenu.FordFulkersonButtonListener;
import taller2.controller.listeners.selectionMenu.HelpButtonListener;
import taller2.controller.listeners.selectionMenu.PrimmButtonListener;
import taller2.controller.listeners.selectionMenu.StronglyConnectedListener;
import taller2.controller.listeners.selectionMenu.TopologicBFSButtonListener;
import taller2.controller.listeners.selectionMenu.TopologicDFSButtonListener;
import taller2.controller.listeners.selectionMenu.TransitiveLockListener;
import taller2.controller.listeners.selectionMenu.AboutUsButtonListener;
import taller2.utils.Point;
import taller2.utils.Utils;
import taller2.view.windows.MyWindow;

public class SelectionMenu extends JPanel{
        private static final long serialVersionUID = 1L;
       
        private JToggleButton dijkstraButton, primmButton;
        private JToggleButton BFSButton, DFSButton;    
        private JToggleButton TopologicBFSButton, TopologicDFSButton;  
        private JToggleButton CycleDetectionButton,FloydButton;
        private JToggleButton transitiveLockButton,stronglyConnectedButton;
        private JToggleButton FordFulkersonButton;
        private JToggleButton helpButton,aboutUsButton;

        // constructor
        public SelectionMenu(MyWindow parent) {
               
                this.dijkstraButton = createButton("Dijkstra",new DijkstraButtonListener(this,parent));
                this.FloydButton = createButton("Floyd",new FloydButtonListener(this,parent));
                this.FordFulkersonButton = createButton("Ford-Fulkerson",new FordFulkersonButtonListener(this,parent));

                this.BFSButton = createButton("Recorrido BFS",new BFSButtonListener(this,parent));
                this.DFSButton = createButton("Recorrido DFS",new DFSButtonListener(this,parent));
                this.TopologicBFSButton = createButton("Topologic width",new TopologicBFSButtonListener(this,parent));
                this.TopologicDFSButton = createButton("Topologic depth",new TopologicDFSButtonListener(this,parent));

                this.primmButton = createButton("Prim",new PrimmButtonListener(this,parent));
                this.transitiveLockButton  = createButton("Transitive closure",new TransitiveLockListener(this,parent));
                this.stronglyConnectedButton = createButton("Str Conn Comp",new StronglyConnectedListener(this,parent));
                this.CycleDetectionButton = createButton("Cycle Detection",new CycleDetectionListener(this,parent));
                this.aboutUsButton = createButton("Authors",new AboutUsButtonListener(this));
                this.helpButton = createButton("help",new HelpButtonListener(this));

                       
                setLayout(new GridBagLayout());

                int cont = 0;
                float weightY = (float)0.1;
                Utils.addComponent(this,BFSButton,1, weightY, new Point(0, cont++));
                Utils.addComponent(this,DFSButton,1, weightY, new Point(0, cont++));

                Utils.addComponent(this,TopologicBFSButton,1, weightY, new Point(0, cont++));
                Utils.addComponent(this,TopologicDFSButton,1, weightY, new Point(0, cont++));

                Utils.addComponent(this,CycleDetectionButton,1, weightY, new Point(0, cont++));
                Utils.addComponent(this,stronglyConnectedButton,1, weightY, new Point(0, cont++));

                Utils.addComponent(this,primmButton,1, weightY, new Point(0, cont++));

                Utils.addComponent(this,dijkstraButton,1, weightY, new Point(0, cont++));
                Utils.addComponent(this,FloydButton,1, weightY, new Point(0, cont++));
                Utils.addComponent(this,transitiveLockButton,1, weightY, new Point(0, cont++));

                Utils.addComponent(this,FordFulkersonButton,1, weightY, new Point(0,cont++));

                Utils.addComponent(this,aboutUsButton,1, weightY, new Point(0, cont++));
                Utils.addComponent(this,helpButton,1, weightY, new Point(0, cont++));
        }
       
    // adds a standard button
    private JToggleButton createButton(String text,ActionListener handler){
            JToggleButton button = new JToggleButton(text);
            button.addActionListener(handler);              
            return button;
    }
               
        // unselects all the buttons
        public void unselectButtons() {
                helpButton.setSelected(false);
                CycleDetectionButton.setSelected(false);
                dijkstraButton.setSelected(false);
                FloydButton.setSelected(false);
                primmButton.setSelected(false);
                BFSButton.setSelected(false);
                DFSButton.setSelected(false);
                TopologicBFSButton.setSelected(false);
                TopologicDFSButton.setSelected(false);
                FordFulkersonButton.setSelected(false);
                transitiveLockButton.setSelected(false);
                stronglyConnectedButton.setSelected(false);
                aboutUsButton.setSelected(false);
        }
   
  }

